<template>
  <div class="goodsinfo">
    <div class="my-panel">
      <Swiper :lunbolist="lunbolist"></Swiper>
    </div>
    <van-panel
      class="my-panel"
      :title="info.title"
    >
      <p class="price">
        <span class="sell_price">现价:{{ info.sell_price }}</span>
        <span class="market_price">原价:{{ info.market_price }}</span>
      </p>
      <div class="num"><span class="num-tit">购买数量:</span> <van-stepper v-model="value" /></div>
    </van-panel>

    <van-panel
      class="my-panel"
      title="商品信息"
    >
      <div class="msg-list">
        <p>商品货号:{{ info.goods_no }}</p>
        <p>库存情况:{{ info.stock_quantity }}</p>
        <p>上架时间:{{ info.add_time | datafmt }}</p>
      </div>
    </van-panel>
    <Comment :id="id"></Comment>
    <van-goods-action>
      <van-goods-action-icon
        icon="chat-o"
        text="客服"
        dot
      />
      <van-goods-action-icon
        icon="cart-o"
        text="购物车"
        :badge="$store.getters['cart/getAllCount']"
        to="/cart"
      />
      <van-goods-action-icon
        icon="shop-o"
        text="店铺"
        badge="12"
      />
      <van-goods-action-button
        type="warning"
        text="加入购物车"
        @click="addCart"
      />
      <van-goods-action-button
        type="danger"
        text="立即购买"
      />
    </van-goods-action>
  </div>
</template>
<script>
import Swiper from '@/components/Swiper';
import Comment from '@/components/Comment';
// import { mapMutations } from 'vuex';
export default {
  components: {
    Swiper,
    Comment,
  },
  props: ['id'],
  data() {
    return {
      value: 0,
      info: {},
      lunbolist: [],
    };
  },
  created() {
    this.getInfo();
    this.getLunbo();
  },
  methods: {
    async getInfo() {
      const res = await this.$http.getInfo(this.id);
      this.info = res.data.message;
    },
    async getLunbo() {
      const res = await this.$http.getThumImages(this.id);
      this.lunbolist = res.data.message;
    },
    addCart() {
      const cartInfo = {
        id: this.id,
        selected: true,
        img: this.lunbolist[0].src,
        title: this.info.title,
        price: this.info.sell_price,
        count: this.value,
      };
      this.$store.commit('cart/addGoods', cartInfo);
    },
  },
};
</script>
<style lang="scss">
.goodsinfo {
  padding: 10px 10px 50px 10px;

  .my-swiper {
    width: 100%;
    height: 170px;
    text-align: center;
    img {
      width: 50%;
      height: 100%;
      vertical-align: middle;
    }
  }
  .my-panel {
    font-size: 12px;
    border: 1px solid #eee;
    margin-bottom: 10px;

    .price {
      padding: 0 15px;
      .sell_price {
        color: red;
        margin-right: 15px;
      }
      .market_price {
        text-decoration: line-through;
      }
    }
    .num {
      padding: 0 15px 10px 15px;
      display: flex;
      align-items: center;
      .num-tit {
        margin-right: 15px;
      }
    }
    .msg-list {
      padding: 0 15px;
    }
  }
}
</style>
